/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.upn.talbd.proventas;

import edu.upn.evolucion.proventas.entidades.Empleado;
import edu.upn.evolucion.proventas.negocio.EmpleadoNEG;
import java.math.BigDecimal;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

/**
 *
 * @author Administrador
 */
public class GestionarEmpleado extends javax.swing.JInternalFrame {

    /**
     * @return the id
     */
    public static int getId() {
        return id;
    }

    /**
     * @param aId the id to set
     */
    public static void setId(int aId) {
        id = aId;
    }

    /**
     * @return the nombre
     */
    public static String getNombre() {
        return nombre;
    }

    /**
     * @param aNombre the nombre to set
     */
    public static void setNombre(String aNombre) {
        nombre = aNombre;
    }

    /**
     * @return the apellidoPaterno
     */
    public static String getApellidoPaterno() {
        return apellidoPaterno;
    }

    /**
     * @param aApellidoPaterno the apellidoPaterno to set
     */
    public static void setApellidoPaterno(String aApellidoPaterno) {
        apellidoPaterno = aApellidoPaterno;
    }

    /**
     * @return the apellidoMaterno
     */
    public static String getApellidoMaterno() {
        return apellidoMaterno;
    }

    /**
     * @param aApellidoMaterno the apellidoMaterno to set
     */
    public static void setApellidoMaterno(String aApellidoMaterno) {
        apellidoMaterno = aApellidoMaterno;
    }

    /**
     * @return the password
     */
    public static String getPassword() {
        return password;
    }

    /**
     * @param aPassword the password to set
     */
    public static void setPassword(String aPassword) {
        password = aPassword;
    }

    /**
     * @return the direccion
     */
    public static String getDireccion() {
        return direccion;
    }

    /**
     * @param aDireccion the direccion to set
     */
    public static void setDireccion(String aDireccion) {
        direccion = aDireccion;
    }

    /**
     * @return the email
     */
    public static String getEmail() {
        return email;
    }

    /**
     * @param aEmail the email to set
     */
    public static void setEmail(String aEmail) {
        email = aEmail;
    }

    /**
     * @return the sueldo
     */
    public static BigDecimal getSueldo() {
        return sueldo;
    }

    /**
     * @param aSueldo the sueldo to set
     */
    public static void setSueldo(BigDecimal aSueldo) {
        sueldo = aSueldo;
    }

    /**
     * @return the cargo
     */
    public static String getCargo() {
        return cargo;
    }

    /**
     * @param aCargo the cargo to set
     */
    public static void setCargo(String aCargo) {
        cargo = aCargo;
    }

    /**
     * Creates new form GestionarEmpleado
     */
    public GestionarEmpleado() {
        initComponents();
    }
    
    private static int id;
    private static String nombre;
    private static String apellidoPaterno;
    private static String apellidoMaterno;
    private static String password;
    private static String direccion;
    private static String email;
    private static BigDecimal sueldo;
    private static String cargo;

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnRegistrar = new javax.swing.JButton();
        btnModificar = new javax.swing.JButton();
        btnEliminar = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        txtNombreBuscarEmpleado = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblEmpleados = new javax.swing.JTable();
        btnBuscarCliente2 = new javax.swing.JButton();
        lblRestriccionSeleccion = new javax.swing.JLabel();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setTitle("Gestionar Empleado");

        btnRegistrar.setText("Registrar");
        btnRegistrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRegistrarActionPerformed(evt);
            }
        });

        btnModificar.setText("Modificar");
        btnModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnModificarActionPerformed(evt);
            }
        });

        btnEliminar.setText("Eliminar");
        btnEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarActionPerformed(evt);
            }
        });

        jLabel5.setText("Nombre:");

        tblEmpleados.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID", "Nombre", "Apellido Paterno", "Apellido Materno", "Direccion", "Email", "Sueldo", "Cargo"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tblEmpleados);

        btnBuscarCliente2.setText("Buscar");
        btnBuscarCliente2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarCliente2ActionPerformed(evt);
            }
        });

        lblRestriccionSeleccion.setForeground(new java.awt.Color(255, 0, 0));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addGap(18, 18, 18)
                        .addComponent(txtNombreBuscarEmpleado, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(btnBuscarCliente2))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 642, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(btnRegistrar, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(btnEliminar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnModificar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addComponent(lblRestriccionSeleccion))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addComponent(btnRegistrar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnModificar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnEliminar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblRestriccionSeleccion)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 93, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(txtNombreBuscarEmpleado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnBuscarCliente2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnRegistrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRegistrarActionPerformed
        // TODO add your handling code here:
        RegistrarEmpleado ventana = new RegistrarEmpleado(null, closable);
        ventana.setVisible(true);
    }//GEN-LAST:event_btnRegistrarActionPerformed

    private void btnModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnModificarActionPerformed
        // TODO add your handling code here:
         TableModel tableModel = getTblEmpleados().getModel();
        int fila = getTblEmpleados().getSelectedRow();
        if(fila == -1){
            lblRestriccionSeleccion.setText("*Seleccione");
        }
        else{
         lblRestriccionSeleccion.setText("");
        setId(Integer.parseInt(tableModel.getValueAt(fila, 0).toString()));
        setNombre(tableModel.getValueAt(fila, 1).toString());
        setApellidoPaterno(tableModel.getValueAt(fila, 2).toString());
        if(tableModel.getValueAt(fila, 3) == null){
            setApellidoMaterno("");
        }
        else{
            setApellidoMaterno(tableModel.getValueAt(fila, 3).toString());
        }
        if(tableModel.getValueAt(fila, 4) == null){
            setDireccion("");
        }
        else{
            setDireccion(tableModel.getValueAt(fila, 4).toString());
        }
        if(tableModel.getValueAt(fila, 5) == null){
            setEmail("");
        }
        else{
            setEmail(tableModel.getValueAt(fila, 5).toString());
        }
        if(tableModel.getValueAt(fila, 6) == null){
            setSueldo(BigDecimal.ZERO);
        }
        else{
            setSueldo(new BigDecimal(tableModel.getValueAt(fila, 6).toString()));
        }
        if(tableModel.getValueAt(fila, 7) == null){
            setCargo("");
        }
        else{
            setCargo(tableModel.getValueAt(fila, 7).toString());
        }
        
        
        ModificarEmpleado ventana = new ModificarEmpleado(null, closable);
        ventana.setVisible(true);
        }

        //setSeleccion(new Cliente(Integer.parseInt(tableModel.getValueAt(fila, 0).toString()), tableModel.getValueAt(fila, 1).toString(), tableModel.getValueAt(fila, 2).toString(), tableModel.getValueAt(fila, 3).toString(), tableModel.getValueAt(fila, 4).toString(), tableModel.getValueAt(fila, 5).toString(), tableModel.getValueAt(fila, 6).toString(), null, tableModel.getValueAt(fila, 7).toString()));
    }//GEN-LAST:event_btnModificarActionPerformed

    private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarActionPerformed
        // TODO add your handling code here:
        int fila = getTblEmpleados().getSelectedRow();
        if(fila == -1){
            lblRestriccionSeleccion.setText("*Seleccione");
        }
        else{
         lblRestriccionSeleccion.setText("");
        int idEmpleado = Integer.parseInt(getTblEmpleados().getValueAt(fila, 0).toString());
        String msg = EmpleadoNEG.obtenerInstancia().eliminar(idEmpleado);
        JOptionPane.showMessageDialog(null, msg);
        }
    }//GEN-LAST:event_btnEliminarActionPerformed

    private void btnBuscarCliente2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarCliente2ActionPerformed
        // TODO add your handling code here:
        ArrayList<Empleado> coleccion = new ArrayList<Empleado>();
        String nombreBuscar = getTxtNombreBuscarEmpleado().getText();

        Empleado objEmpleado = new Empleado();
        objEmpleado.setNombre(nombreBuscar);
        coleccion =EmpleadoNEG.obtenerInstancia().buscar(objEmpleado);
        DefaultTableModel temp = (DefaultTableModel) getTblEmpleados().getModel();
        temp.setRowCount(0);
        for(Empleado e : coleccion){
            //System.out.println(“Nombre del Empleado: ” + tmpObjeto.getNombre());
            Object nuevo[] ={e.getId(), e.getNombre(), e.getApellidoPaterno(), e.getApellidoMaterno(), e.getDireccion(), e.getEmail(), e.getSueldo(), e.getCargo()};
            temp.addRow(nuevo);
        }
    }//GEN-LAST:event_btnBuscarCliente2ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBuscarCliente2;
    private javax.swing.JButton btnEliminar;
    private javax.swing.JButton btnModificar;
    private javax.swing.JButton btnRegistrar;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblRestriccionSeleccion;
    private javax.swing.JTable tblEmpleados;
    private javax.swing.JTextField txtNombreBuscarEmpleado;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the btnBuscarCliente2
     */
    public javax.swing.JButton getBtnBuscarCliente2() {
        return btnBuscarCliente2;
    }

    /**
     * @param btnBuscarCliente2 the btnBuscarCliente2 to set
     */
    public void setBtnBuscarCliente2(javax.swing.JButton btnBuscarCliente2) {
        this.btnBuscarCliente2 = btnBuscarCliente2;
    }

    /**
     * @return the btnEliminar
     */
    public javax.swing.JButton getBtnEliminar() {
        return btnEliminar;
    }

    /**
     * @param btnEliminar the btnEliminar to set
     */
    public void setBtnEliminar(javax.swing.JButton btnEliminar) {
        this.btnEliminar = btnEliminar;
    }

    /**
     * @return the btnModificar
     */
    public javax.swing.JButton getBtnModificar() {
        return btnModificar;
    }

    /**
     * @param btnModificar the btnModificar to set
     */
    public void setBtnModificar(javax.swing.JButton btnModificar) {
        this.btnModificar = btnModificar;
    }

    /**
     * @return the btnRegistrar
     */
    public javax.swing.JButton getBtnRegistrar() {
        return btnRegistrar;
    }

    /**
     * @param btnRegistrar the btnRegistrar to set
     */
    public void setBtnRegistrar(javax.swing.JButton btnRegistrar) {
        this.btnRegistrar = btnRegistrar;
    }

    /**
     * @return the jLabel5
     */
    public javax.swing.JLabel getjLabel5() {
        return jLabel5;
    }

    /**
     * @param jLabel5 the jLabel5 to set
     */
    public void setjLabel5(javax.swing.JLabel jLabel5) {
        this.jLabel5 = jLabel5;
    }

    /**
     * @return the jScrollPane1
     */
    public javax.swing.JScrollPane getjScrollPane1() {
        return jScrollPane1;
    }

    /**
     * @param jScrollPane1 the jScrollPane1 to set
     */
    public void setjScrollPane1(javax.swing.JScrollPane jScrollPane1) {
        this.jScrollPane1 = jScrollPane1;
    }

    /**
     * @return the tblEmpleados
     */
    public javax.swing.JTable getTblEmpleados() {
        return tblEmpleados;
    }

    /**
     * @param tblEmpleados the tblEmpleados to set
     */
    public void setTblEmpleados(javax.swing.JTable tblEmpleados) {
        this.tblEmpleados = tblEmpleados;
    }

    /**
     * @return the txtNombreBuscarEmpleado
     */
    public javax.swing.JTextField getTxtNombreBuscarEmpleado() {
        return txtNombreBuscarEmpleado;
    }

    /**
     * @param txtNombreBuscarEmpleado the txtNombreBuscarEmpleado to set
     */
    public void setTxtNombreBuscarEmpleado(javax.swing.JTextField txtNombreBuscarEmpleado) {
        this.txtNombreBuscarEmpleado = txtNombreBuscarEmpleado;
    }
}
